<template>
  <div class="app-container">

    <el-form ref="form" :model="model" label-width="120px">

      <el-form-item hidden="hidden" disabled="disabled" label="id">
        <el-input v-model="model.id" disabled="disabled" />
      </el-form-item>

      <el-form-item label="密码">
        <el-input v-model="model.password" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">确认修改</el-button>
        <el-button type="info" @click="back">返回</el-button>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>

import { getOne, updatePassword } from '@/api/system/user'
export default {
  data() {
    return {
      model: {
      }
    }
  },
  async created() {
    const id = this.$route.params.id
    if (!id) {
      return
    }
    const { data } = await getOne(id)
    this.model = data
  },
  methods: {
    async onSubmit() {
      console.log(this.model)
      let res
      if (this.model.id) {
        res = await updatePassword(this.model).then({})
      }
      if (res.code === 0) {
        this.$message.success('操作成功')
        this.back()
      }
    },
    back() {
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>
